package com.gustuy.chat;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class URLDown {

    public static void main(String[] args) throws Exception{
        //URL
        URL url=new  URL("https://m10.music.126.net/20210507154733/1abd816c4ed92a6152cd76afff7f1524/yyaac/obj/wonDkMOGw6XDiTHCmMOi/1682376542/7f8b/9ccf/4125/d5897bb189b0cc3e00f2f7dcc0c56239.m4a");
        //连接
        HttpURLConnection urlConnection =(HttpURLConnection) url.openConnection();
        InputStream in=urlConnection.getInputStream();
        FileOutputStream fileOutputStream=new FileOutputStream("d5897bb189b0cc3e00f2f7dcc0c56239.m4a");
        byte[] buffer=new byte[1024];
        int len;
        while ((len=in.read(buffer))!=-1){
            fileOutputStream.write(buffer,0,len);
        }
        fileOutputStream.close();
        in.close();
        urlConnection.disconnect();
    }
}
